package com.atguigu.lease.web.app.custom.interceptor;

import com.atguigu.lease.common.Exceptions.LeaseException;
import com.atguigu.lease.common.jwtUtils.JwtUtil;
import com.atguigu.lease.common.result.ResultCodeEnum;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @Author zy
 * @Date 2024/12/16
 * @Desc
 * @Version 1.0
 */
@Component
public class AuthenticationInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("access_token");
        if (token==null){
            //没有token 未登录
            throw new LeaseException(ResultCodeEnum.APP_LOGIN_AUTH);
        }
        System.out.println("token = " + token);
        JwtUtil.parseToken(token);
        return true;
    }
}
